const mysql = require("mysql2");

const service = {
  find(username, password) {
    try {
      const promisePool = mysql.createPool(getDBConfig()).promise();
      return promisePool.query(
        `select username from user where username=? && password=?`,
        [username, password]
      );
    } catch (error) {
      return [];
    }
  },
};

module.exports = service;
function getDBConfig() {
  return {
    host: "127.0.0.1",
    user: "root",
    port: "3306",
    password: "",
    database: "chat",
    connectionLimit: 1,
  };
}
